package com.seal.yoyoshop.web;

import com.seal.yoyoshop.bin.Order;
import com.seal.yoyoshop.bin.Type;
import com.seal.yoyoshop.bin.User;
import com.seal.yoyoshop.service.TypeService;
import com.seal.yoyoshop.service.impl.TypeServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "CartServlet", value = "/index/cart")
public class CartServlet extends HttpServlet {
    TypeService typeService = new TypeServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        if(user == null){
//            response.sendRedirect("/yoyoshop_war_exploded/index/login");
            //找的相对路径
            response.sendRedirect("login");
        }else{
        //        导航栏
        List<Type> typeList = typeService.getTypeList();
        request.setAttribute("typeList",typeList);

        //        转发
        request.getRequestDispatcher("/index/cart.jsp").forward(request,response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
